package com.example.wechat_b.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.example.wechat_b.activity.ChatActivity;
import com.example.wechat_b.utils.Custom;
import com.example.wechat_b.R;

import java.util.List;

/**
 * @author liaoqg
 * @brief description
 * @date 2021-11-01
 */
public class MainChatListAdapter extends BaseAdapter {

    private Context context;
    private List<Custom> list;
//    private SqliteDatabaseHelper sqliteDatabaseHelper;
//    private SQLiteDatabase db;

    static {

    }

    public MainChatListAdapter(Context context,List<Custom> list){
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

//    public int getSqlItemId(){
//        return
//    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Custom custom = list.get(position);
        switch (custom.TYPE){
            case 0x01:
                convertView = LayoutInflater.from(context).inflate(R.layout.custom_item,parent,false);
                ImageView cusImg = convertView.findViewById(R.id.cus_item_img);
                Glide.with(context)
                        .load(R.mipmap.xjp)
                        .transform(new CircleCrop())
                        .into(cusImg);
                TextView tv1 = convertView.findViewById(R.id.cus_item_toke);
                tv1.setText(custom.toke);
                break;
            case 0x02:
                convertView = LayoutInflater.from(context).inflate(R.layout.mine_item,parent,false);
                ImageView minImg = convertView.findViewById(R.id.min_item_img);
                Glide.with(context)
                        .load(R.mipmap.mine)
                        .transform(new CircleCrop())
                        .into(minImg);
                TextView tv2 = convertView.findViewById(R.id.min_item_toke);
                tv2.setText(custom.toke);
                break;
            case 0x03:
                convertView = LayoutInflater.from(context).inflate(R.layout.time_item,parent,false);
                TextView tv3 = convertView.findViewById(R.id.time_item_text);
                tv3.setText(custom.time);
                break;
        }


        convertView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                Toast.makeText(context,"1",Toast.LENGTH_LONG).show();
                return false;
            }
        });

//        ViewHolder viewHolder;
//        if (convertView == null){
//            viewHolder = new ViewHolder();
//            switch (list.get(position).TYPE){
//                case 0x01:
//                    convertView = LayoutInflater.from(context).inflate(R.layout.custom_item,parent,false);
////                    viewHolder.img = convertView.findViewById(R.id.cus_item_img);
//                    viewHolder.take = convertView.findViewById(R.id.cus_item_toke);
//                    break;
//                case 0x02:
//                    convertView = LayoutInflater.from(context).inflate(R.layout.mine_item,parent,false);
////                    viewHolder.img = convertView.findViewById(R.id.min_item_img);
//                    viewHolder.take = convertView.findViewById(R.id.min_item_toke);
//                    break;
//                case 0x03:
//                    convertView = LayoutInflater.from(context).inflate(R.layout.time_item,parent,false);
//                    viewHolder.time = convertView.findViewById(R.id.time_item_text);
//                    break;
//            }
//            convertView.setTag(viewHolder);
//        }else {
//            viewHolder = (ViewHolder) convertView.getTag();
//        }
//        if (list.get(position)!=null){
//
//        }
//        Custom custom = list.get(position);
//        if (custom.TYPE == 0x01){
//            viewHolder.take.setText(custom.toke == null? "": custom.toke);
//        }else if (custom.TYPE == 0x02){
//            viewHolder.take.setText(custom.toke == null? "": custom.toke);
//        }else{
//            viewHolder.time.setText(custom.time);
//        }
//        switch (custom.TYPE){
//            case 0x01 :
////                viewHolder.img.setImageResource(custom.img);
//                viewHolder.take.setText(custom.toke == null? "": custom.toke);
//                break;
//            case 0x02 :
////                viewHolder.img.setImageResource(custom.img);
//                viewHolder.take.setText(custom.toke == null? "": custom.toke);
//                break;
//            case 0x03:
//                viewHolder.time.setText(custom.time);
//        }
        return convertView;
    }
    class ViewHolder{
        public ImageView img;
        public TextView take,time;
    }
}
